﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using System.Threading;


namespace CustomAction
{
    [RunInstaller(true)]
    public partial class InstallerClassDll : Installer
    {
        private string SetupExpand = "SetupExpand.exe";

        public InstallerClassDll()
        {
            InitializeComponent();
        }

        protected override void OnAfterInstall(System.Collections.IDictionary savedState)
        {
            base.OnAfterInstall(savedState);

            string rootPath = Context.Parameters["rootpath"];

            string setupPath = Path.Combine(rootPath, SetupExpand);
            RunSetupExpand(rootPath, setupPath);
        }

        private void RunSetupExpand(string rootPath, string setupPath)
        {
            if (File.Exists(setupPath))
            {
                Process myProcess = new Process();
                ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(setupPath);
                myProcessStartInfo.UseShellExecute = false;
                myProcessStartInfo.CreateNoWindow = false;
                myProcessStartInfo.RedirectStandardOutput = false;
                myProcess.StartInfo = myProcessStartInfo;
                myProcessStartInfo.Arguments = rootPath;
                myProcess.Start();
                myProcess.WaitForExit();
                myProcess.Close();
            }
        }
    }
}
